import fpgl from '{platform}/script/views/tjzx/fpgl/index';
import {tbody,tleftInfo,tcount} from '{platform}/script/views/table/tableData'
import tableObj from '{platform}/script/pages/table/index';
import search from '{platform}/script/pages/search/index';
var template=require('template');
var events=require('events');
var request = require('{pub}/request');
var func = require('{pub}/function');
var message = require('{layer}/message');
return {
    target:'#fpgl',
    path:'/fpgl/',
    template:fpgl, 
    tbHead:{
        leftType:'info',
        bottomCount:false,
        headArr:[{
            name:'单据编号',type:'djbh',width:100
        },{
            name:'所属税局',type:'c_companyname',width:85
        },{
            name:'发票类型',type:'fptype',width:85
        },{
            name:'发票种类',type:'fpzl',width:85
        },{
            name:'开票日期',type:'kprq',width:85
        },{
            name:'发票代码',type:'fpdm',width:85
        },{
            name:'发票号码',type:'fphm',width:100
        },{
            name:'付款方名称',type:'fkfmc',width:120
        },{
            name:'付款方税号',type:'fkfzjhm',width:100
        },{
            name:'申请人名称',type:'skfmc',width:120
        },{
            name:'申请人身份证号码',type:'skfzjhm',width:120
        },{
            name:'申请人电话',type:'skflxdh',width:120
        },{
            name:'申请人地址',type:'skfdz',width:120
        },{
            name:'合计金额',type:'wsjehj',width:85
        },{
            name:'合计税额',type:'sehj',width:85,countdata:'sehj'
        },{
            name:'价税合计',type:'hsjehj',width:85
        },{
            name:'备注',type:'bz',width:85
        }]
    },
    onInit:function(){
        var _that =  this
        var funList=[];
        var slideList={
            rows:4,
            arr:[{
                name:'单据编号',
                type:'djbh',
                data:'input',
            },{
                name:'开票日期',
                type:'time',
                data:'date'
            },{
                name:'发票代码',
                type:'fpdm',
                data:'input',
            },{
                name:'发票号码',
                type:'fphm',
                data:'input'
            },{
                name:'付款方名称',
                type:'fkfmc',
                data:'input'
            },{
                name:'付款方税号',
                type:'fkfzjhm',
                data:'input'
            },{
                name:'申请人名称',
                type:'skfmc',
                data:'input'
            },{
                name:'申请人身份证号',
                type:'skfzjhm',
                data:'input'
            },{
                name:'所属税局',
                type:'bmid',
                data:'ztree',
                // option:comoption
            },{
                name:'发票类型',
                type:'fptype',
                data:'option',
                option:[{
                    id:0,
                    value:'正票'
                },{
                    id:1,
                    value:'红票'
                },{
                    id:2,
                    value:'重开正票'
                }]
            },{
                name:'发票种类',
                type:'fpzl',
                data:'option',
                option:[{
                    id:'0',
                    value:'增值税专用发票'
                },{
                    id:'51',
                    value:'增值税电子普通发票'
                },{
                    id:'2',
                    value:'增值税纸质普通发票'
                }]
            }]
        };
        var param = {//导出功能参数
            all:'/tjzx/gssk/export',
            gssk:'/tjzx/gssk/exportGssk'
        }//
        search.init(_that.element.find('.g-top-view'), {funList:funList,slideList:slideList}, param);
        tableObj.init(_that.element.find('.g-table-view'),{tabHead:this.tbHead},{_that:this,url:'/tjzx/fpgl/list',param:{query:'y'},callback:this.reqFpgl})
        // this.reqGssk()
    },
    reqFpgl:function(res) {//国税税款统计
        var that = this._that;
        if(res.result === 'success') {
            console.log(res.data)
            var rows = res.data.rows;
            // var footList = res.data.footerList;
            that.tableData(rows)
        } else {
            message('error', res.message)
        }
    },
    tableData:function(data,footList) {//表格数据处理
        var _that = this,tbHead = this.tbHead.headArr;
            var i,len = data.length, j, jlen = tbHead.length, tbBody = [],countHsjehj = 0,countSehj = 0;
            for(i=0;i<len;i++) {
                countSehj = func.jisuan('+',countSehj,data[i].sehj);
                countHsjehj = func.jisuan('+',countHsjehj,data[i].hsjehj);
                tbBody.push({
                    id:data[i].pdfurl || '',
                    td:[],
                });
                for(j =0;j<jlen;j++) {
                    if(tbHead[j].type === 'status') {
                        data[i][tbHead[j].type]= data[i][tbHead[j].type] === 2 ? '已结算':'拟结算'
                    }
                    if(tbHead[j].type === 'fptype') {
                        if(data[i][tbHead[j].type] === 0) {
                            data[i][tbHead[j].type] = '正票'
                        } else if(data[i][tbHead[j].type] === 1) {
                            data[i][tbHead[j].type] = '红票'
                        } else if(data[i][tbHead[j].type] === 2) {
                            data[i][tbHead[j].type] = '重开正票'
                        }
                    }
                    if(tbHead[j].type === 'fpzl') {
                        if(data[i][tbHead[j].type] === '51') {
                            data[i][tbHead[j].type] = '增值税普通电子发票'
                        } else if(data[i][tbHead[j].type] === '0' ) {
                            data[i][tbHead[j].type] = '增值税纸质专用发票'
                        } else if(data[i][tbHead[j].type] === '2' ){
                            data[i][tbHead[j].type] = '增值税纸质电子发票'
                        }
                    }
                    if(tbHead[j].type === 'type') {
                        if(data[i][tbHead[j].type] === 1) {
                            data[i][tbHead[j].type] = '支付宝'
                        } else if(data[i][tbHead[j].type] === 3 ) {
                            data[i][tbHead[j].type] = '微信'
                        } else if(data[i][tbHead[j].type] === 2 ){
                            data[i][tbHead[j].type] = 'H5微信'
                        }
                    }
                    tbBody[i].td.push({
                        name:data[i][tbHead[j].type] || '',
                        type:tbHead[j].type
                    });
                }
            }
            console.log(tbBody)
            $('#tableData').html(template.render(tbody, {tabBody:tbBody}));
            $('#tfixData').html(template.render(tleftInfo, {tabBody:tbBody}));
            // $('#tcountData').html(template.render(tcount, {tabCount:tabCount}));
    }
}